import MyDrawer from './MyDrawer.vue'

// this.$myDrawer()
// .vue组件，想把他变为一个函数，然后new 他 构造函数，$mount()

// install -> Vue.use()
export default {
  install(Vue) {
    // 1. 将组件变为函数
    const Drawer = Vue.extend(MyDrawer)

    const notice = (options = {}) => {
      console.log('options:', options)
      const data = {
        visible: true,
      }

      const instance = new Drawer({
        propsData: options,
        data,
      }).$mount()
      console.log('instance:', instance)
      // 打开弹出框
      instance.show = true
      document.body.appendChild(instance.$el)
      return instance
    }

    Vue.prototype.$notice = notice

    // 既能函数调用，也能组件调用
    // Vue.component('MyDrawer', Drawer)
  },
}
